package com.wx.rabbitmq.exchange.direct;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.wx.rabbitmq.MqConnection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import static com.wx.rabbitmq.exchange.direct.ConsumerDirectExchange.EXCHANGE_DIREC;
import static com.wx.rabbitmq.exchange.direct.ConsumerDirectExchange.ROUTING_DIREC_KEY;


/**
 * @author wx
 * @Description: 生产者-交换机direct(直连模式)
 * @date 2018/11/23 002313:48
 */
public class ProducerDirectExchange {
    public static void main(String[] agrs) throws IOException, TimeoutException {
        //1.获取connection
        Connection connection = MqConnection.getConnection();

        //2.通过connection创建一个Channel
        Channel channel = connection.createChannel();
        //3 通过Channel发送数据   exchange=交换机、 2 routingKey=队列对应的key、3 props = 消息装饰器、 4=消息体
        String msg = "Hello RabbitMQ Direct Exchange Message!";
        channel.basicPublish(EXCHANGE_DIREC, ROUTING_DIREC_KEY, null, msg.getBytes());
        //4 记得要关闭相关的连接
        channel.close();
        connection.close();
    }
}
